<?php

namespace lico\Tool\Log;

class File
{

    protected static $folder;

    public static function save($module, $msg, $filename)
    {

        self::$folder = constant("SYSCONFIG")['Log']['main'];

        if (!is_dir(ROOT_PATH . self::$folder . DS . $module)) {
            mkdir(ROOT_PATH . self::$folder . DS . $module, 0777, true);
        }

        $todayFolder = date('Y-m-d', time());
        if (!is_dir(ROOT_PATH . self::$folder . DS . $module . DS . $todayFolder)) {
            mkdir(ROOT_PATH . self::$folder . DS . $module . DS . $todayFolder, 0777, true);
        }

        if (is_array($msg)) {
            $msg = var_export($msg, true);
        }
        $msg = $msg . "\r\n";

        $file = ROOT_PATH . self::$folder . DS . $module . DS . $todayFolder . DS . $filename . '.log';
        $write = @file_put_contents($file, $msg, FILE_APPEND);

        return $write;
    }
}
